package Java练习.面向对象综合练习.多态.综合练习;

public class Person {
    private String name;
    private int age;
    //构造方法

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    //定义get和set方法


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    //定义行为喂狗/猫
    public void keepPet(Animal animal,String something){
        if (animal instanceof Dog dog){
            System.out.println("年龄为"+age+"的"+name+"养了一只"+animal.getColor()+"狗");
            dog.eat(something);
        } else if (animal instanceof Cat c) {
            System.out.println("年龄为"+age+"的"+name+"养了一只"+animal.getColor()+"猫");
            c.eat(something);
        }else {
            System.out.println("没有这个动物");
        }
    }
}
